<?php

namespace App\Admin\Renderable;

use App\Models\AgricGoods;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class AgricGoodsTable extends LazyRenderable
{
    public function grid(): Grid
    {
        $regionId = $this->payload['region_id'];

        return Grid::make(new AgricGoods(), function (Grid $grid) use ($regionId) {
            if ($regionId) {
                $grid->model()->where('region_id', $regionId);
            }
            $grid->column('id', 'ID')->sortable();
            $grid->column('goods_name', '商品名称');
            $grid->column('goods_img')->image('', 60, 60);
            $grid->column('created_at');

            $grid->quickSearch(['id', 'goods_name', 'goods_img']);

            $grid->paginate(10);
            $grid->disableActions();
        });

    }
}